package com.zach.common.action.file;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.zach.common.action.BaseAction;

@Component
@Scope("request")
public class FileUploadAction extends BaseAction {
	private static final long serialVersionUID = -6707699480381822673L;
	private static Log log = LogFactory.getLog(FileUploadAction.class.getName());
	private File file;
	private String toPage;
	Map<String, Object> map ;
	public String fileUpload() throws Exception {
//		map = new HashMap<String, Object>();
		String msg ;
		log.info("toPage:"+toPage);
		if(null != file){
			log.info("file:"+file.getAbsolutePath());
//			map.put("code", JSON_OK);
//			map.put("msg", "文件上传成功！"+file.getName());
			msg = "文件上传成功！"+file.getName();
		}else{
			log.warn("文件没有上传成功！");
//			map.put("code", JSON_ERROR);
//			map.put("msg", "文件上传失败，没有取到文件！");
			msg = "文件上传失败，没有取到文件！";
		}
		ServletActionContext.getResponse().getWriter().print(msg);
		return NONE;
	}
	
	@Override
	public String execute() throws Exception {
		return super.execute();
	}

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public String getToPage() {
		return toPage;
	}

	public void setToPage(String toPage) {
		this.toPage = toPage;
	}
	
	
}
